using System;

namespace FridayShopping.DataModel
{
	/// <summary>
	/// Product category. Holds the name of the category. It also holds
	/// in memory only (not seralized) all the products of this category
	/// So it will be easier to organize it it that way.
	/// </summary>
	public class Category : ItemBase 
	{		
		private Products	products;

		#region Constructors
		public Category()
		{
		}

		public Category(string name) : base (name)
		{
		}
		#endregion

		#region Member Access
		public Products Products
		{
			get
			{
				if (products == null)
				{
					products = new Products();
				}
				return products;
			}
			set 
			{
				products = value;
			}
		}
		#endregion

	}

	/// <summary>
	/// Holds the list of categories. Each item in this list is a 'Category'
	/// </summary>
	[ListItemTypeAttribute(typeof(Category))]
	public class Categories : ItemListBase
	{
		#region Constructor
		public Categories()
		{
		}
		#endregion

		public Products ProductsByCategory
		{
			get 
			{
				Products productList = new Products();

				productList.NextKey = Database.Instance.Products.NextKey;

				foreach(Category category in this.List)
				{
					foreach(Product product in category.Products.List) 
					{
						productList.AddWithKey(product);
					}
				}
				return productList;
			}
		}
	}
}
